Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dumps the ported typer tests and adds appropriate testing mechanisms. #1574

Draft
wants to merge 1 commit into
base: v1
Choose a base branch
from

Conversation

johnedquinn
Copy link
Member

@johnedquinn johnedquinn commented Sep 3, 2024

Description

  • Dumps the ported typer tests and adds appropriate testing mechanisms.

Structure

  • The testing structure is as follows:
    • Tests reside in resources under tests
    • Tests are serialized as Ion structs and have three mandatory fields: name, type, and body. The type is used to request the TestBuilderFactory which TestBuilder to use. The name, in combination with the path to the test file, is used to create a TestId. The body (a struct) is passed to the TestBuilder to allow for user-defined tests.
    • The newly introduced TyperTests just invokes the TestProvider to deserialize the tests and shuttle them through JUnit.
  • This should provide adequate flexibility for executing varying test types.

Other Information

License Information

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These slight changes made it easier to serialize the tests.

import org.partiql.planner.test.TestProviderBuilder
import java.util.stream.Stream

class TyperTests {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the replacement for PlanTyperTestsPorted.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to confirm all of the existing tests are included in TyperTests?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These were unused.

@johnedquinn johnedquinn marked this pull request as ready for review September 3, 2024 18:59
Copy link
Member

@alancai98 alancai98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job w/ porting the tests! Most comments/questions were about some missing context and possible simplifications

import org.partiql.planner.test.TestProviderBuilder
import java.util.stream.Stream

class TyperTests {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to confirm all of the existing tests are included in TyperTests?

fun print() {
val other = PlanTyperTestsPorted.TestProvider().provideArguments(null).map { it.get()[0] as PlanTyperTestsPorted.TestCase }.toList()
val testCases =
other + PlanTyperTestsPorted.collections() + PlanTyperTestsPorted.decimalCastCases() + PlanTyperTestsPorted.selectStar() + PlanTyperTestsPorted.sessionVariables() + PlanTyperTestsPorted.bitwiseAnd() + PlanTyperTestsPorted.unpivotCases() + PlanTyperTestsPorted.joinCases() + PlanTyperTestsPorted.excludeCases() + PlanTyperTestsPorted.orderByCases() + PlanTyperTestsPorted.tupleUnionCases() + PlanTyperTestsPorted.aggregationCases() + PlanTyperTestsPorted.scalarFunctions() + PlanTyperTestsPorted.distinctClauseCases() + PlanTyperTestsPorted.pathExpressions() + PlanTyperTestsPorted.caseWhens() + PlanTyperTestsPorted.nullIf() + PlanTyperTestsPorted.coalesce() + PlanTyperTestsPorted.subqueryCases() + PlanTyperTestsPorted.dynamicCalls() + PlanTyperTestsPorted.scanCases() + PlanTyperTestsPorted.pivotCases() + PlanTyperTestsPorted.isTypeCases() + PlanTyperTestsPorted.castCases()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this currently spans one line. could break it up for better readability

Comment on lines +3 to +14
interface Test {

/**
* @return the name of the test.
*/
fun getName(): String

/**
* Should throw an exception if a failure occurs.
*/
fun assert()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we foresee future Test implementations other than TyperTest? I feel like it's slight overkill to have a broader Test interface.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. The reason we'd like to do this is to create a starting point by which we may serialize all of our tests in a uniform manner. For execution, typing, etc.

* @see StructElement
* @see PartiQLTestProvider
*/
interface TestBuilder {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly for the TestBuilder and TestBuilderFactory, seems like a lot of additional boilerplate unless we foresee adding more than the typing tests within partiql-planner?

Comment on lines +9 to +10
cwd:[
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The vast majority of the typing tests use an empty session directory list. Wonder if we could simplify the logic by making a non-specified cwd equivalent to an empty session directory list.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this! I'll update.

@@ -23,6 +23,7 @@ import kotlin.io.path.toPath
* The PartiQLTestProvider is a simple utility for indexing SQL statements within files for re-use across library tests.
*/
class PartiQLTestProvider {
// TODO: Rename this to StatementProvider to better reflect its purpose
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could address in this PR?

Comment on lines +13 to +19
private fun getQualifier(): Array<String> {
return _qualifier
}

private fun getName(): String {
return _name
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these getters necessary? Since this is just in the tests, this indirection is not needed. I feel like it would be much simpler to just directly reference the _qualifer and _name.

@@ -0,0 +1,6717 @@

test::{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point could be helpful to break into different files and/or namespaces like the conformance tests currently do. We could track in some TODO/issue.

}
}

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could provide the description of the test format in some other more visible location such as https://github.com/johnedquinn/partiql-lang-jvm/blob/v1-tests-dump/partiql-planner/src/testFixtures/resources/README.adoc.

Something like https://github.com/partiql/partiql-tests/blob/main/docs/partiql-tests-schema-proposal.md#evaluation-tests, could make it easier to add future tests.

@@ -0,0 +1,236 @@
package org.partiql.planner
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had some broader questions for porting the typing tests since I may be missing some context.

  1. Is the goal here to eventually delete the PlanTyperTestsPorted (and related files)?
  2. Where will the ported typing tests eventually live? In the conformance test suite?
  3. At what point will we delete the existing PlanTyperTestsPorted (and related files)?
  4. For future plan typing tests we want to add, what's the process for adding a test? Just add the test to the plan-typer-tests-ported.ion file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Yes.
  2. I'd personally like to extract these interfaces into another package: test/partiql-test-interfaces that can be imported as a test dependency across the project. Any particular subproject may have local serialized tests -- and once the team agrees upon the tests' correctness, they can be moved into the conformance test suite. If you'd like, I can move these interfaces immediately in this PR.
  3. The only open action item for PlanTyperTestsPorted has to do with the serialization of errors, which is being worked on. I actually don't need to keep it right now. I can always resurface the PrintPlanTyperTestsPorted from an older commit to re-serialize when the error serialization is addressed.
  4. You can add a test to the tests directory in any file you'd like.

@johnedquinn johnedquinn marked this pull request as draft September 19, 2024 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants